﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data;

namespace MyVocationSpace
{
    public partial class CreateTopic : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {           
            BAL.conn.connectionString = ConfigurationManager.ConnectionStrings["connectionstring"].ConnectionString;
            if (Session["UserID"] == null)
            {
                Response.Redirect("Home.aspx");
            }
            else
            {
                if (!IsPostBack)
                {
                    int UserId = Convert.ToInt32(Session["UserID"].ToString());
                    BAL.Vocation.PopulateVocation(UserId, ref ddlVocation);                    
                }

                DataSet ds = BAL.Users.GetIndustryByUser(Convert.ToInt32(Session["UserID"]));
                lblIndustry.Text = ds.Tables[0].Rows[0][0].ToString();
                HdnIDIndustry.Value = ds.Tables[0].Rows[0][1].ToString();
                ViewState["HdnIDIndustry"] = HdnIDIndustry.Value;
            }
        }



        
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string name = txtName.Text;
            int vocationID=Convert.ToInt32(ddlVocation.SelectedValue);
            string description = txtDescription.Text;
            int UserId = Convert.ToInt32(Session["UserID"].ToString());
            int topicId = BAL.Vocation.InsertBlogTopic(name, Convert.ToInt32(ViewState["HdnIDIndustry"]), vocationID, description, UserId);
            int IsMentor = BAL.Vocation.SelectIsMentor(topicId);
            Span1.Style.Add("Display", "block");
            Span1.InnerHtml = "Record Inserted Successfully";
            //Response.Redirect("~/Blog.aspx?topicId=" + topicId + "&IsMentor=" + IsMentor);      // As per Client's Email
            Response.Redirect("MyVocation.aspx");
            clear();
        }
        public void clear()
        {
            txtName.Text = "";
            txtDescription.Text = "";
        }
    }
}